package com.fly.uaa.security.token;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class SocialVerificationAuthenticationToken extends AbstractAuthenticationToken {
    private static final long serialVersionUID = 7798979258977335359L;
    private final Object principal;
    private Object credentials;
    private String account_type;


    public SocialVerificationAuthenticationToken(Object principal, Object credentials, String account_type) {
        super((Collection)null);
        this.principal = principal;
        this.credentials = credentials;
        this.account_type = account_type;
        this.setAuthenticated(false);
    }

    public SocialVerificationAuthenticationToken(Collection<? extends GrantedAuthority> authorities, Object principal, Object credentials, String
            account_type) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.account_type = account_type;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (isAuthenticated) {
            throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
        } else {
            super.setAuthenticated(false);
        }
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        this.credentials = null;
    }

    public String getAccount_type() {
        return account_type;
    }

    public void setAccount_type(String account_type) {
        this.account_type = account_type;
    }
}
